Belgelerim/ceng_491/implementation/doxygen/TraffEdu_Developers_Manual_Reference_ToSource/MFCKeyboardMouseCallbacktime.h

Go to the documentation of this file.
00001 
00006 class MFCKeyboardMouseCallbacktime : public Producer::KeyboardMouseCallback
00007 {
00008 public:
00009 
00014     MFCKeyboardMouseCallbacktime(osgUtil::SceneView* sceneView) :
00015         Producer::KeyboardMouseCallback(),
00016         _mx(0.0f),
00017                 _my(0.0f),
00018                 _mbutton(0),
00019         _trackBall(new Producer::Trackball),
00020         _sceneView(sceneView)
00021     {
00022         resetTrackball();
00023     }
00024 
00028         void home()
00029         {
00030                 resetTrackball();
00031         }
00032         
00036     virtual void keyPress( Producer::KeyCharacter key)
00037     {
00038         if (key==' ') resetTrackball();
00039     }
00040 
00044     virtual void mouseMotion( float mx, float my ) 
00045     {
00046         _mx = mx;
00047         _my = my;
00048     }
00049         
00053     virtual void buttonPress( float mx, float my, unsigned int mbutton ) 
00054     {
00055          _mx = mx;
00056          _my = my;
00057          _mbutton |= (1<<(mbutton-1));
00058          
00059          _mx_buttonPress = _mx;
00060          _my_buttonPress = _my;
00061     }
00062 
00063         
00067     virtual void buttonRelease( float mx, float my, unsigned int mbutton ) 
00068     {
00069         _mx = mx;
00070         _my = my;
00071         _mbutton &= ~(1<<(mbutton-1));
00072     }
00073 
00078     float mx()  { return _mx; }
00079 
00084     float my()  { return _my; }
00085 
00090     unsigned int mbutton()  { return _mbutton; }
00091     
00095     void resetTrackball()
00096     {
00097         osg::Node* scene = _sceneView->getSceneData();
00098         if (scene)
00099         {
00100             const osg::BoundingSphere& bs = scene->getBound();
00101             _trackBall->reset();
00102             _trackBall->setOrientation( Producer::Trackball::Z_UP );
00103                         _trackBall->setDistance(bs.radius());
00104             _trackBall->translate(-bs.center().x(),-bs.center().y(),-bs.center().z());
00105                         _trackBall->translate(-bs.center().x(),-bs.center().y(),0);
00106         }
00107     }
00112     osg::Matrixd getViewMatrix()
00113     {
00114                 _trackBall->input( mx(), my(), mbutton() );
00115         return osg::Matrixd(_trackBall->getMatrix().ptr());
00116     }
00117 
00118 private:
00119 
00120     float                               _mx, _my;
00121     float                               _mx_buttonPress, _my_buttonPress;
00122     unsigned int                        _mbutton;
00123     
00124     osg::ref_ptr<Producer::Trackball>   _trackBall;
00125     osg::ref_ptr<osgUtil::SceneView>    _sceneView;
00126 };

Generated on Sun May 28 18:54:09 2006 for TraffEdu by  doxygen 1.4.6-NO